# 日志工具
import logging
import os


class LogUtils:
    @staticmethod
    def get_logger():
        """获取日志记录器"""
        logger = logging.getLogger("test_logger")
        logger.setLevel(logging.DEBUG)

        """创建日志文件目录"""
        log_dir = "logs"
        os.makedirs(log_dir, exist_ok=True)

        """文件处理器"""
        file_handler = logging.FileHandler(f"{log_dir}/test.log", encoding="utf-8")
        file_handler.setLevel(logging.DEBUG)

        """控制台处理器"""
        console_handler = logging.StreamHandler()
        console_handler.setLevel(logging.INFO)

        """日志格式"""
        formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
        file_handler.setFormatter(formatter)
        console_handler.setFormatter(formatter)

        """添加处理器"""
        logger.addHandler(file_handler)
        logger.addHandler(console_handler)

        return logger
